ב' פתרון בחינת הבגרות פרק א - tg Together double x 5.0 int from 2 int to 6 One first Two second One n 5.0 Queue<One>q שאלה : א. One n 4.0 One n 8.0 One n 6.0 One n 32.0 new Two ((from,to) n m i i<m 2 i 2 6 2 T 4 3 T 8 4 T 6 5 T 32 6 F פלט הפעולה main() methoda() methodb() println first.f() println first,g() second.f() -- MethodA() -- f of One -- MethodB -- g of One 5.0 f of Two 4.0 ב. אם התור לא ריק, מוציאה את האיבר שבראש התור ומדפיסה את ערכו בצירוף הודעה. ואם התור ריק, מדפיסה רק את ההודעה. אין משמעות להנחה ששני המספרים גדולים מ- 0. ההנחה צריכה להתייחס למספרים השני והשלישי המקיימים: השלישי גדול מהראשון.
2 a.length = 5 0 2 3 4 a 2 4 7 2 8 שאלה 2: א. (a,) sod ערך k i i<4 j j<5 a[i] a[j] a[i]+a[j] == k מוחזר 0 T T 2 4 F 2 T 7 F 3 T 2 F 4 T 8 F 5 F אמת T 2 T 4 7 T ב. (a,0) sod ערך k i i<4 j j<5 a[i] a[j] a[i]+a[j] == k מוחזר 0 0 T T 2 4 F 2 T 7 F 3 T 2 F 4 T 8 F 5 F T 2 T 4 7 F 3 T 2 F 4 T 8 F 5 F 2 T 3 T 7 2 F 4 T 8 F 5 F 3 T 4 T 2 8 F 5 F שקר 4 F
3 ג. ד. ה. הפעולה מחזירה "אמת" אם קיימים שני איברים במערך שסכומם k, ו- "שקר" אחרת. סיבוכיות הפעולה sod היא ) 2.O(n בהנחה שיש במערך n איברים: הלולאה החיצונית רצה על כל המערך - סה"כ n צעדים ובתוכה לולאה פנימית הרצה בכל פעם על איבר אחד פחות: 2 n ( n ) n n ( n ) ( n 2) ( n 3)... 2 Sn O( n 2 2 2 ) what (a, k) a.length = 5 0 2 3 4 a 2 4 7 2 8 k left right left<right I a[left] II a[right] I+II == k I+II < k 0 4 T 2 8 F F 3 T 2 F F 2 T 7 F T ערך מוחזר אמת T 4 T.O(n) what ו. סיבוכיות הפעולה היא הפעולה עוברת לכל היותר מעבר אחד על כל נתוני המערך, עד שמוצאת או לא מוצאת שני איברים שסכומם k. O(n 2 ) O(n) ז. סיבוכיות הפעולה - sod ריבועית סיבוכיות הפעולה - what ליניארית ולכן, what יעילה יותר. )( )2( ח. sod תשיג את מטרתה, כי היא בודקת בכל פעם איבר אחר מול כולם. what לא תשיג את המטרתה, כי היא אינה בודקת את כל האפשרויות. למשל: עבור המערך הבא תחזיר sod "אמת", ואילו what תחזיר "שקר". 0 2 3 4 a 8 2 4 7 2
4 שאלה 3: א. ההוראה מצב התור לאחר האתחול [] q.insert () [] q.insert (2) [, 2] q.insert (3) [, 2, 3] q.remove() [2, 3] q.insert (4) [2, 3, 4] q.undo() [2, 3] q.undo() [, 2, 3] סעיף א' לאחר הרצת התכנית: start : [] [] 0 for remove for insert 2 for undo - to end --> type a number --> op : [] [(,)] 0 for remove for insert 2 for undo - to end --> type a number --> 2 op : [, 2] [(2,), (,)] 0 for remove for insert 2 for undo - to end --> type a number --> 3 op : [, 2, 3] [(3,), (2,), (,)] 0 for remove for insert 2 for undo - to end --> 0 op 0: [2, 3] [(,0), (3,), (2,), (,)] 0 for remove for insert 2 for undo - to end --> type a number --> 4 op : [2, 3, 4] [(4,), (,0), (3,), (2,), (,)] 0 for remove for insert 2 for undo - to end --> 2 op 2: [2, 3] [(,0), (3,), (2,), (,)] 0 for remove for insert 2 for undo - to end --> 2 op 2: [, 2, 3] [(3,), (2,), (,)] 0 for remove for insert 2 for undo - to end --> -
5 /* מחלקה המגדירה פעולה עבור * Undo */ public class Item הערך // val; private int הפעולה :,insert private int op; // remove :0 java: /* * QueueUndo תור- ביטול */ public class UndoQueue private Queue <Integer> que; private Stack<Item> stk; תור הפעולות // מחסנית ה - undo // public UndoQueue() this.que = new Queue<Integer>(); this.stk = new Stack<Item>(); --- הכנסה לתור ביטול ---// public void insert(int x) this.que.insert(x); this.stk.push(new Item(x,)); --- הוצאה מתור ביטול ---// public int remove() int x = this.que.remove(); this.stk.push(new Item(x,0)); return x; --- פעולת //--- undo public void undo() if(!stk.isempty()) Item item = this.stk.pop(); if (item.getop() == 0) undoremove (item.getval()); else undoinsert (); --- הוצאת הערך שנמצא בסוף התור ---// --- הנחה: התור לא ריק ---//
6 private void undoinsert() --- דחיפת סימן לתור ---// int sign = -; this.que.insert(sign); // כל איברי התור חיוביים. מספר שלילי מהווה סימן טוב // --- העברת כל האיברים פרט לאחרון לסוף התור ---// int x = this.que.remove(); boolean finish = false; while (! finish) if (this.que.head() == sign) this.que.remove(); finish = true; else this.que.insert(x); x = this.que.remove(); --- הכנסת ערך לתחילת התור ---// private void undoremove(int x) Queue<Integer>q = new Queue<Integer>(); דחיפת הערך לתחילת תור העזר // q.insert(x); --- העברת כל האיברים לתור העזר ---// while (! this.que.isempty()) q.insert(this.que.remove()); החזרת האיברים מתוך העזר לתור המקורי ---// while (! q.isempty()) this.que.insert(q.remove());
7 /* מחלקה המגדירה פעולה עבור * Undo */ public class Item הערך // val; private int הפעולה :,insert private int op; // remove :0 C#: /* * QueueUndo תור- ביטול */ public class UndoQueue private Queue <int> que; private Stack<Item> stk; תור הפעולות // מחסנית ה - undo // public UndoQueue() this.que = new Queue<int>(); this.stk = new Stack<Item>(); --- הכנסה לתור ביטול ---// public void Insert(int x) this.que.insert(x); this.stk.push(new Item(x,)); --- הוצאה מתור ביטול ---// public int Remove() int x = this.que.remove(); this.stk.push(new Item(x,0)); return x; --- פעולת //--- undo public void Undo() if(!stk.isempty()) Item item = this.stk.pop(); if (item.getop() == 0) UndoRemove (item.getval()); else UndoInsert ();
8 --- הוצאת הערך שנמצא בסוף התור ---// ---// ריק --- הנחה: התור לא private void UndoInsert() --- דחיפת סימן לתור ---// int sign = -; this.que.insert(sign); // כל איברי התור חיוביים. מספר שלילי מהווה סימן טוב // --- העברת כל האיברים פרט לאחרון לסוף התור ---// int x = this.que.remove(); bool finish = false; while (! finish) if (this.que.head() == sign) this.que.remove(); finish = true; else this.que.insert(x); x = this.que.remove(); --- הכנסת ערך לתחילת התור ---// private void UndoRemove(int x) Queue<int> q = new Queue<int>(); דחיפת הערך לתחילת תור העזר // q.insert(x); --- העברת כל האיברים לתור העזר ---// while (! this.que.isempty()) q.insert(this.que.remove()); החזרת האיברים מתוך העזר לתור המקורי ---// while (! q.isempty()) this.que.insert(q.remove());
9 פתרון אחר: מחסנית ה- undo היt מחסנית שכל איבר בה הוא מסוג תור. בכל פעם שמתבצעת פעולה על תור-ביטול נוצר עותק של התור והוא מוכנס למחסנית. בכל פעם שמתבצעת פעולת undo מקבל תור-ביטול הפנייה לתור שנשלף מראש המחסנית. הערה: פתרון זה אינו יעיל כי הוא בזבזני במקום. אחרי n פעולות על התור )ללא )undo יהיה במחסנית n תורים שתופסים הרבה מאוד מקום בזיכרון. למימוש זה קראתי QueueUndo )ולא Undo Queu כנדרש בשאלה( public class QueueUndo private Queue <Integer> que; java: תור הפעולות // מחסנית ה - undo private Stack<Queue<Integer>> stk; // public QueueUndo() this.que = new Queue<Integer>(); this.stk = new Stack<Queue<Integer>>(); --- הכנסה לתור ביטול ---// public void insert(int x) this.que.insert(x); this.stk.push(copyqueue()); --- הוצאה מתור ביטול ---// public int remove() int x = this.que.remove(); this.stk.push(copyqueue()); return x; --- פעולת //--- undo public void undo() if(!stk.isempty()) Queue<Integer>q = this.stk.pop(); this.que = copyqueue(); --- פעולה המחזירה העתק של התור- ביטול ---// private Queue<Integer> copyqueue() Queue<Integer> q = new Queue<Integer>(); Queue<Integer> qtmp = new Queue<Integer>(); while (! this.que.isempty()) int x = this.que.remove(); q.insert(x); qtmp.insert(x); while (! qtmp.isempty()) this.que.insert(qtmp.remove()); return q;
0 public class QueueUndo private Queue<int> que; private Stack<Queue<int>> stk; תור הפעולות // מחסנית ה - undo // C# : public QueueUndo() this.que = new Queue<int>(); this.stk = new Stack<Queue<int>>(); --- הכנסה לתור ביטול ---// public void Insert(int x) this.que.insert(x); this.stk.push(copyqueue()); --- הוצאה מתור ביטול ---// public int Remove() int x = this.que.remove(); this.stk.push(copyqueue()); return x; --- פעולת //--- undo public void Undo() if (!stk.isempty()) Queue<int> q = this.stk.pop(); this.que = CopyQueue(); --- פעולה המחזירה העתק של התור- ביטול ---// private Queue<Integer> CopyQueue() Queue<int> q = new Queue<int>(); Queue<int> qtmp = new Queue<int>(); while (!this.que.isempty()) int x = this.que.remove(); q.insert(x); qtmp.insert(x); while (!qtmp.isempty()) this.que.insert(qtmp.remove()); return q;
סעיף א' לאחר הרצת התכנית באפשרות - מחסנית של תורים: start : [] [] 0 for remove for insert 2 for undo - to end --> type a number --> op : [] [[]] 0 for remove for insert 2 for undo - to end --> type a number --> 2 op : [, 2] [[, 2], []] 0 for remove for insert 2 for undo - to end --> type a number --> 3 op : [, 2, 3] [[, 2, 3], [, 2], []] 0 for remove for insert 2 for undo - to end --> 0 op 0: [2, 3] [[2, 3], [, 2, 3], [, 2], []] 0 for remove for insert 2 for undo - to end --> type a number --> 4 op : [2, 3, 4] [[2, 3, 4], [2, 3], [, 2, 3], [, 2], []] 0 for remove for insert 2 for undo - to end --> 2 op 2: [2, 3, 4] [[2, 3], [, 2, 3], [, 2], []] 0 for remove for insert 2 for undo - to end --> 2 op 2: [2, 3, 4] [[, 2, 3], [, 2], []] 0 for remove for insert 2 for undo - to end --> -
2 java: :4 --- ט.כניסה: עץ בינארי לא ריק ומחסנית ריקה של מספרים ---// --- ט.יציאה: המחסנית מכילה את ערכי העלים בסריקה מימין לשמאל ---// public static void leaves (BinTreeNode<Integer>t, Stack<Integer>s) if (t!= null) if (isleaf(t)) s.push(t.getinfo()); else leaves(t.getright(), s); leaves(t.getleft(), s); שאלה --- האם עלה? //--- --- הנחה : bt אינו //-- null public static boolean isleaf (BinTreeNode <Integer> bt) if (bt.getleft() == null && bt.getright() == null) return true; return false; --- ט.כניסה: 2 עצים בינאריים המכילים מספרים שלמים ---// --- ט.יציאה: "אמת" אם מספר וערכי העלים ב- 2 העצים שווים ---// --- ו-"שקר" אחרת ---// public static boolean chktrees ( BinTreeNode <Integer> t, BinTreeNode <Integer> t2) Stack <Integer> s = new Stack<Integer>(); Stack <Integer> s2 = new Stack<Integer>(); leaves(t, s); leaves(t2, s2); --- השוואת ערכי העלים שבשתי המחסניות ---// while (! s.isempty() &&! s2.isempty()) if (s.pop()!= s2.pop()) return false; --- אם אחת המחסניות התרוקנה לפני הזמן ---// if (! s.isempty()! s2.isempty()) return false; return true;
3 --- ט.כניסה: עץ בינארי לא ריק ומחסנית ריקה של מספרים ---// --- ט.יציאה: המחסנית מכילה את ערכי העלים בסריקה מימין לשמאל ---// public static void Leaves (BinTreeNode<int>t, Stack<int>s) if (t!= null) if (IsLeaf(t)) s.push(t.getinfo()); else Leaves(t.GetRight(), s); Leaves(t.GetLeft(), s); --- האם עלה? //--- --- הנחה : bt אינו //-- null public static bool IsLeaf (BinTreeNode <int> bt) if (bt.getleft() == null && bt.getright() == null) return true; return false; --- ט.כניסה: 2 עצים בינאריים המכילים מספרים שלמים ---// --- ט.יציאה: "אמת" אם מספר וערכי העלים ב- 2 העצים שווים ---// --- ו-"שקר" אחרת ---// public static bool ChkTrees (BinTreeNode <int> t, BinTreeNode <int> t2) Stack <int> s = new Stack<int>(); Stack <int> s2 = new Stack<int>(); Leaves(t, s); Leaves(t2, s2); --- השוואת ערכי העלים שבשתי המחסניות ---// while (! s.isempty() &&! s2.isempty()) if (s.pop()!= s2.pop()) return false; --- אם אחת המחסניות התרוקנה לפני הזמן ---// if (! s.isempty()! s2.isempty()) return false; return true; C# :
4 פרק ב' מערכות מחשב ואסמבלר תרגיל 5: תרגיל 6: תרגיל 7: שאלה 8:
5 פרק ב' מבוא לחקר ביצועים שאלה 9: שאלה 0: שאלה : שאלה 2:
6 פרק ב' מודלים חישוביים הפתרון לפרק זה נכתב ע"י רחל לודמר. תרגיל 3: n=, עבור k= ab 4 c א. המילה הקצרה היא ב. ללא שינוי/, a דחוף b, / S דחוף b,s/ A דחוף b,a/ A ללא שינוי/ b,s ללא שינוי/ b,a ללא שינוי/, b ללא שינוי/, a שלוף c,s /S שלוף c,a /A ללא שינוי/ b,s ללא שינוי/ b,a שלוף c,s /S שלוף c,a /A
7 q 0 a q a a a זוגי a זוגי b אי זוגי b זוגי b q 3 q 4 b a שאלה 4: a אי זוגי b זוגי b q 2 b a זוגי b אי זוגי b a a q 5 a b b q 6 a אי זוגי b אי זוגי השלמת האוטומט נעזרה במקרא הבא: a אי זוגי b זוגי - מצב התחלה q 0 מספר ה- a אי זוגי ומספר ה- b זוגי. - q מספר ה- a זוגי ומספר ה- b אי זוגי. - q 2 מספר ה- a זוגי ומספר ה- b זוגי. - q 3 - מספר ה- a זוגי ומספר ה- b אי זוגי. q 4 מספר ה- a אי זוגי ומספר ה- b זוגי. - q 5 מספר ה- a אי זוגי ומספר ה- b אי זוגי. - q 6 q q q b b a a b b 0 q3 q4 q q2 q3 q4 a b a a 0 q q3 q q2 b b 0 q3 q4 ב.. (i) המילה aaba לא מתקבלת. (ii) המילה bbaabb מתקבלת. (iii) המילה abaa מתקבלת. (iv) המילה bb מתקבלת. השפה L המוגדרת ע"י האוטומט היא אוסף כל המילים מעל הא"ב אותיות זהות. a,b שמסתיימות לפחות בשתי.2
8 שאלה 5: n k L 0 2 n k 0 א. הוכחה שהשפה אינה רגולרית. נוכיח שהשפה L היא אי רגולרית, בדרך השלילה. נניח שהשפה רגולרית וקיים אוטומט סופי דטרמיניסטי A הבונה אותה. תהי הקבוצה האינסופית הבאה: התחלות של מילים בשפה L i j.w מתוך הקבוצה w 0, w2 0 i j, נבחר שתי התחלות שונות, j 0 מאחר והאוטומט הוא סופי ניתן להניח כי שתי המילים מגיעות למצב משותף q t באוטומט. A משם נשרשר כל מילה עם הרצף 2 3 n W 0, 0, 0,...,0,.... q r. שתי המילים מגיעות למצב משתף i 2 0 i עבור i>j שייכת לשפה, ולכן q מצב מקבל. מאחר ויש להם מסלול משותף, j r המילה 2 0 i גם בשפה, וזה בניגוד לכללי השפה. יוצא גם ש- i 2 לכן הנחתנו ששתי המילים מגיעות למצב משתף אינה נכונה, אלא כל מילה מגיעה למצב אחר. ומאחר והקבוצה W היא אינסופית יוצא שכל מילה מגיע למצב אחר. ומכאן יש אינסוף מצבים ב-, A בניגוד להגדרת אוטומט סופי. לכן ההנחה שקיים אוטומט סופי הבונה את השפה L אינה נכונה, והשפה אינה רגולרית. ואילו השפה L,(n>0) השפה. L L החיתוך הוא השפה הריקה. השפה L חייבת להתחיל באות 0 את הספרה 0. ב. אינה מכילה כלל
9 שאלה 6: א. מסלולו חישוב עבור (3)f q 0 a f(3) = '' q a q 2 a q 2 a q 3 a q 6 a q 6 q 5 a q a q 4 q 7 ב. '' = f(5) בסוף הפעולה נקבל ג. '' = f(6) בסוף הפעולה נקבל
20 מטרת הפונקציה 2/x f(x) = )החלק השלם(. עבור x זוגי נקבל 2/x ועבור x אי זוגי נקבל 2/(-x) ד. ימין, /. q 0 יש להוסיף את המעבר q7, f(0) ה. כדי לקבל את אפשרות אחרת: / a, q 0 ימין להוסיף את המעבר q
2 Java פרק ב' תכנות מונחה עצמים תרגיל 7: הבדיקה לא חובה. אם ערך התא null הפעולה instanceof תחזיר שקר
22 תרגיל 8: class A numa 0 2 class B numb 0 2 3 class D numd 0 2 B w numb ++ B w2 numb ++ ++ numd B w3 numb ++ ++ numd B m 2 m2 3 D m 6 m2 6 d.5 D m 8 m2 9 d 2.3 A A A w4 A a // A w5 A a numa ++ B b numa ++ B b B(2, 3), # B(6, 6), #2 D(.5, 6), # B(8, 9), #3 D(2.3, 8, 9), #2 פלט: A Constructor, # A Constructor, #2
23 תרגיל 9: aseq n i i < 4 א. פלט 5 elements: 2, 5, 8,, 4 The sequence כן 0 ASeq כן first 2 diff 3 2 3 4 כן כן לא public class Sequence protected int first; public Sequence(int first) this.first = first; ב. public int thenelement(int n) return this.first; public void displaynelements(int n) System.out.print("The sequence elements"); for (int i = ; i < n ; i++) System.out.print(this.first + ","); System.out.println(this.first); האיבר האחרון מודפס ללא סימן פסיק אחריו השינויים במחלקה :ASeq public class ASeq extends Sequence // המחלקה מרחיבה את Sequence private int difference; // מוגדר במחלקת העל first public ASeq(int first, int difference) אתחול first ב- super(first); // super this.difference = difference; : // כל שאר המחלקה ללא שינוי : // כל פעולה מגדירה מחדש את הפעולות של מחלקת העל כך שיתאים לסדרה הנוכחית
24 ג. יש לממש את הפעולה סכום-הסדרה במחלקה.Sequance המחלקות היורשות יכולות להשתמש בפעולה ללא צורך בשינויים, כל אחת תממש את הפעולה לפי הפעולה thenelement המוגדרת בה. public int sumseq(int n) int sum = 0; for (int i = ; i <= n ; i++) sum += thenelement(i); return sum; //------ comparing sumsequences ------- public static char check (int n, ASeq sqa, GSeq sqg) int suma = sqa.sumseq(n); int sumg = sqg.sumseq(n); ד. if (suma > sumg) return 'A'; if (suma < sumg) return 'G'; return 'E';
25 שאלה 20: הפעולות נתונות ואין צורך לרשום אותן בפתרון א א א ב
26 א א א ב
27 פרק ב' תכנות מונחה עצמים #C הפתרון לפרק זה נכתב ע"י זיוה קונצמן תרגיל 2: public virtual bool IsLike(Object obj) return obj is AA &&((AA)obj).GetSt().Equals(this.GetSt()); public override bool IsLike(object obj) return obj is BB && ((BB)obj).GetNum()==this.GetNum(); א. במחלקה :AA ב. במחלקה : BB ג. קטע התוכנית נכון. מתבצעת המרה אוטומטית כלפי מעלה של משתנה מטיפוס הבן להפניה מטיפוס האב. הבן הוא גם טיפוס האב לכן אין בעיה. st = excellent num = ד. הפלט יהיה: קטע התוכנית שגוי. לא יכול להמיר כלפי מטה הפניה מסוג האב להיות הפניה מסוג הבן, הוא לא נוצר כ- BB אלא כ-,AA ואינו יכול לעבור המרה למשהו שהוא לא. השגיאה היא שגיאת קומפילציה. public static string LongString(Object[] a) string st = ""; for (int i = 0; i < st.length; i++) if (a[i] is AA &&!(a[i] is BB)) st += ((AA)a[i]).GetSt(); else if (a[i] is BB) for (int j = ; j < ((BB)a[i]).GetNum(); j++) st += ((BB)a[i]).GetSt(); return st; ה.
28 תרגיל 22: w: B B m=2 m2=3 w2: B D m=6 m2=3 d=.5 w3: B D m=8 m2=9 d=2.3 w4: A A a=null b= w5: A A a= b= הפלט:
29 תרגיל 23: א. aseq: ASeq Aseq first=2 difference=3 The sequence elements 2,5,8,,4 הפלט: public class Sequence protected int first; public Sequence(int first) this.first = first; public virtual int TheNElement(int n) return this.first; public virtual void DisplayNElement(int n) Console.Write("The sequence elements"); for (int i = 0; i < n; i++) Console.Write(this.first + ","); ב.. public class ASeq:Sequence private int difference; public ASeq(int first, int difference):base(first) this.difference = difference; public override int TheNElement(int n).2
30 return this.first + (n - ) * this.difference; public override void DisplayNElement(int n) Console.Write("The sequence elements"); for (int i = 0; i < n - ; i++) Console.Write(this.TheNElement(i + ) + ","); Console.WriteLine(this.TheNElement(n)); public int SumSeq(int n) int sum = 0; for (int i = ; i <= n; i++) sum += TheNElement(i); return sum; ג. אין צורך לעשות כל שינוי. הפעולה תכתב במחלקת Sequence כך: בשתי המחלקות היורשות אין צורך בכתיבה מחודשת, כל אחת תממש את חישוב האיבר לפי הפעולה הכתובה בה, מכיוון שכאן יופעל מנגנון הדריסה. public static char Bigger(int n, ASeq a, Gseq g) int s = a.sumseq(n); int s2 = g.sumseq(n); if (s > s2) return 'A'; if (s2 > s) return 'G'; return 'E'; ד.
3 שאלה 24: public class Vet private int id; private string name; private int vetek; עדכון הוותק של הוטרינר ב- // SetVetek() public void this.vetek++; public class Animal private int numr; private string name; private string sug; private int age; private int numvet; private Appointement[] lastvisits; עדכון הגיל של החיה בשנה//() SetAge public void this.age++; public Appointment[] GetLastVisits() return this.lastvisits; public class Appointement private string kodes; private int idvet;
32 public class Clinic private Vet[] veterinarians; private Animal[] animals; הפעולה מקבלת סוג חיה ומדפיסה דו"ח הכולל את פרטי כל החיות מסוג זה // public void AllAnimalsSameKind(string kind) int i = 0; while (i < 500 && animals[i]!= null) if (animals[i].gettype().equals(kind)) Console.WriteLine(animals[i].GetName() + "," + animals[i].getnumr() + "," + animals[i].getage()); i++; הפעולה מעדכנת בשנה את הותק של כל הוטרינרים // public void UpdateVetek() int i = 0; while (i < 0 && veterinarians[i]!= null) this.veterinarians[i].setvetek(); i++; הפעולה מעדכנת בשנה את גיל כל החיות // public void UpdateAgeAnimals() int i = 0; while (i < 50 && animals[i]!= null) this.animals[i].setage(); i++;
33 הפעולה מקבלת ת.ז. של וטרינר ומחזירה את שמו// public string GetVet(int id) int i = 0; while (i < 0 && veterinarians[i]!= null) if (veterinarians[i].getid() == id) return veterinarians[i].getname(); i++; return null; הפעולה מקבלת חיה, וטרינר מטפל וקוד טיפולים נוכחי ומוסיפה את // הביקור למאגר הביקורים הקיים של חיה זו // public void AddAppointment(Animal p, string t, Vet v) int i = 0; while (i < 50 &&!animals[i].equals(p)) i++; Appointment[] a = animals[i].getlastvisits(); i = 0; while (a[i]!= null) i++; a[i] = new Appointment(v, t);